// ------------- 普通接口 -----------------
interface IPerson { 
    firstName:string, 
    lastName:string, 
    sayHi: ()=>string 
} 
 
var customer:IPerson = { 
    firstName:"Tom",
    lastName:"Hanks", 
    sayHi: ():string =>{return "Hi there"} 
} 

// ------------ 联合类型接口 ---------------
interface RunOptions { 
    program:string; 
    commandline:string[]|string|(()=>string); 
} 
 
// commandline 是字符串
var options:RunOptions = {program:"test1",commandline:"Hello"}; 
console.log(options.commandline)  
 
// commandline 是字符串数组
options = {program:"test1",commandline:["Hello","World"]}; 
var arr:string[] = options.commandline as string[]
console.log(arr[0]);  
 
// commandline 是一个函数表达式
options = {program:"test1",commandline:()=>{return "**Hello World**";}}; 
 
var fn:any = options.commandline; 
console.log(fn());

// ---------- 接口继承 -------------
interface IParent1 { 
    v1:number 
    sayHi: ()=>string 
} 
 
interface IParent2 { 
    v2:number 
} 
 
class Child implements IParent1, IParent2 { 
    v1: number;
    v2: number;

    constructor(v1:number, v2:number){
        this.v1 = v1
        this.v2 = v2
    }

    sayHi():string{
        return " say hi"
    }
} 

var Iobj:Child = new Child(1,2)
console.log("value 1: "+Iobj.v1+" value 2: "+Iobj.v2 + "  sayHi():" + Iobj.sayHi())
